from dynamic_scraper.spiders.django_spider import DjangoSpider
from models import (
    MotorSite,
    MotorSubSite, MotorSubSiteItem,
    Car, CarItem,
)


class MotorSubSiteSpider(DjangoSpider):

    name = 'motorsubsite_spider'

    def __init__(self, *args, **kwargs):
        self._set_ref_object(MotorSite, **kwargs)
        self.scraper = self.ref_object.scraper
        self.scrape_url = self.ref_object.url
        self.scheduler_runtime = self.ref_object.scraper_runtime
        self.scraped_obj_class = MotorSubSite
        self.scraped_obj_item_class = MotorSubSiteItem
        super(MotorSubSiteSpider, self).__init__(self, *args, **kwargs)


class CarSpider(DjangoSpider):

    name = 'car_spider'

    def __init__(self, *args, **kwargs):
        self._set_ref_object(MotorSubSite, **kwargs)
        self.scraper = self.ref_object.scraper
        self.scrape_url = self.ref_object.url
        self.scheduler_runtime = self.ref_object.scraper_runtime
        self.scraped_obj_class = Car
        self.scraped_obj_item_class = CarItem
        super(CarSpider, self).__init__(self, *args, **kwargs)
